// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedVehicleStory;

import java.util.ArrayList;
import zombie.characters.IsoZombie;
import zombie.core.Rand;
import zombie.iso.IsoChunk;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaGrid;
import zombie.iso.Vector2;
import zombie.iso.objects.IsoDeadBody;
import zombie.vehicles.BaseVehicle;

public final class RVSCrashHorde extends RandomizedVehicleStoryBase {
    public RVSCrashHorde() {
        this.name = "Crash Horde";
        this.minZoneWidth = 8;
        this.minZoneHeight = 8;
        this.setChance(1);
        this.setMinimumDays(60);
    }

    @Override
    public void randomizeVehicleStory(IsoMetaGrid.Zone zone, IsoChunk chunk) {
        this.callVehicleStorySpawner(zone, chunk, 0.0F);
    }

    @Override
    public boolean initVehicleStorySpawner(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean debug) {
        VehicleStorySpawner vehicleStorySpawner = VehicleStorySpawner.getInstance();
        vehicleStorySpawner.clear();
        float _float = (float) (Math.PI / 6);
        if (debug) {
            _float = 0.0F;
        }

        Vector2 vector2 = IsoDirections.N.ToVector();
        vector2.rotate(Rand.Next(-_float, _float));
        vehicleStorySpawner.addElement("vehicle1", 0.0F, 0.0F, vector2.getDirection(), 2.0F, 5.0F);
        vehicleStorySpawner.setParameter("zone", zone);
        vehicleStorySpawner.setParameter("burnt", Rand.NextBool(5));
        return true;
    }

    @Override
    public void spawnElement(VehicleStorySpawner spawner, VehicleStorySpawner.Element element) {
        IsoGridSquare isoGridSquare = element.square;
        if (isoGridSquare != null) {
            float _float = element.z;
            IsoMetaGrid.Zone zone = spawner.getParameter("zone", IsoMetaGrid.Zone.class);
            boolean _boolean = spawner.getParameterBoolean("burnt");
            String string0 = element.id;
            switch (string0) {
                case "vehicle1":
                    BaseVehicle baseVehicle = this.addVehicleFlipped(
                        zone, element.position.x, element.position.y, _float + 0.25F, element.direction, _boolean ? "normalburnt" : "bad", null, null, null
                    );
                    if (baseVehicle != null) {
                        int int0 = Rand.Next(4);
                        String string1 = null;
                        switch (int0) {
                            case 0:
                                string1 = "Front";
                                break;
                            case 1:
                                string1 = "Rear";
                                break;
                            case 2:
                                string1 = "Left";
                                break;
                            case 3:
                                string1 = "Right";
                        }

                        baseVehicle = baseVehicle.setSmashed(string1);
                        baseVehicle.setBloodIntensity("Front", Rand.Next(0.7F, 1.0F));
                        baseVehicle.setBloodIntensity("Rear", Rand.Next(0.7F, 1.0F));
                        baseVehicle.setBloodIntensity("Left", Rand.Next(0.7F, 1.0F));
                        baseVehicle.setBloodIntensity("Right", Rand.Next(0.7F, 1.0F));
                        ArrayList arrayList = this.addZombiesOnVehicle(Rand.Next(2, 4), null, null, baseVehicle);
                        if (arrayList != null) {
                            for (int int1 = 0; int1 < arrayList.size(); int1++) {
                                IsoZombie isoZombie = (IsoZombie)arrayList.get(int1);
                                isoZombie.upKillCount = false;
                                this.addBloodSplat(isoZombie.getSquare(), Rand.Next(10, 20));
                                if (_boolean) {
                                    isoZombie.setSkeleton(true);
                                    isoZombie.getHumanVisual().setSkinTextureIndex(0);
                                } else {
                                    isoZombie.DoCorpseInventory();
                                    if (Rand.NextBool(10)) {
                                        isoZombie.setFakeDead(true);
                                        isoZombie.bCrawling = true;
                                        isoZombie.setCanWalk(false);
                                        isoZombie.setCrawlerType(1);
                                    }
                                }

                                new IsoDeadBody(isoZombie, false);
                            }

                            this.addZombiesOnVehicle(Rand.Next(12, 20), null, null, baseVehicle);
                        }
                    }
            }
        }
    }
}
